﻿using System;

namespace Gmantis.Controls.Chart
{
    public class AxisPoint
    {
        // Fields
        private Axis _axis;
        private object _item;
        private double _value;

        // Methods
        internal AxisPoint(Axis axis, double value, object item)
        {
            this._axis = axis;
            this._value = value;
            this._item = item;
        }

        public override string ToString()
        {
            if (this._item is string)
            {
                return (string)this._item;
            }
            return this.FormattedValue;
        }

        // Properties
        public Axis Axis
        {
            get
            {
                if (this._axis == null)
                {
                    return null;
                }
                return this._axis;
            }
        }

        public object DataObject
        {
            get
            {
                return this._item;
            }
        }

        public string FormattedLogBase
        {
            get
            {
                if (this._axis == null)
                {
                    return "";
                }
                if (this._axis.LogBase == 2.7182818284590451)
                {
                    return "e";
                }
                if (double.IsNaN(this._axis.LogBase))
                {
                    return "";
                }
                return this._axis.LogBase.ToString();
            }
        }

        public string FormattedValue
        {
            get
            {
                if (this._axis != null)
                {
                    return this._axis.Format(this.Value);
                }
                return this.Value.ToString();
            }
        }

        public double LogBase
        {
            get
            {
                if (this._axis != null)
                {
                    return this._axis.LogBase;
                }
                return double.NaN;
            }
        }

        public double LogValue
        {
            get
            {
                if (double.IsNaN(this.LogBase))
                {
                    return this._value;
                }
                return Math.Log(this._value, this.LogBase);
            }
        }

        public double Value
        {
            get
            {
                return this._value;
            }
        }
    }
}
